package models

/*
	CREATE TABLE `blog_auth` (
	  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
	  `username` varchar(50) DEFAULT '' COMMENT '账号',
	  `password` varchar(50) DEFAULT '' COMMENT '密码',
	  PRIMARY KEY (`id`)
	) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
*/
type Auth struct {
	ID       int    `gorm:"primary_key" json:"id"`
	UserName string `gorm:"column:username"`
	PassWord string `gorm:"column:password"`
}

func CheckAuth(username, password string) (*Auth, error) {
	auth := &Auth{}
	err := db.Select("id,username").
		Where(Auth{UserName: username, PassWord: password}).
		First(auth).Error
	if auth.ID > 0 {
		return auth, nil
	}

	return nil, err
}
